package be.kuleuven.cs.mume.objects;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;
import org.mt4j.util.math.Vector3D;
import org.mt4j.util.math.Vertex;

import processing.core.PApplet;
import advanced.physics.physicsShapes.PhysicsPolygon;

public class PhysicsEllipse extends PhysicsPolygon {

	public PhysicsEllipse(float rX, float rY, int seg, Vector3D position, PApplet applet, World world, float density, float friction, float restitution, float worldScale) {
		super(PhysicsEllipse.tesselate(rX, rY, seg), position, applet, world, density, friction, restitution, worldScale);
		List<Vertex[]> list = new ArrayList<Vertex[]>();
		Vertex[] vert = new Vertex[this.vertices.length+1];
		System.arraycopy(this.vertices, 0, vert, 0, this.vertices.length);
		vert[this.vertices.length] = (Vertex) this.vertices[0].getCopy();
		list.add(vert);
		this.setOutlineContours(list);
		
	}
	
	private static Vertex[] tesselate(float rX, float rY, int seg){
		Vertex[] vertex = new Vertex[seg];
		for(int i = 0; i < seg; i++){
			vertex[i] = new Vertex((float)Math.cos(i * 2*Math.PI/seg) * rX, (float)Math.sin(i * 2*Math.PI/seg) * rY);
		}
		return vertex;
	}
	
	@Override
	protected void bodyDefB4CreationCallback(BodyDef def) {
		super.bodyDefB4CreationCallback(def);
//		def.linearDamping = 0.15f;
		def.linearDamping =0.5f;
		//def.isBullet = true;
		//def.angularDamping = 0.05f;

		//def.allowSleep = true;
		def.fixedRotation = true;
	}

}
